#!/usr/bin/perl

require "accounts.pl";

&ReadParse();

#my (%ogroup, %group, $error_msg, $local_members, $not_local_members, $umembers, $groupname, $gid);
#my ($entry_local_members, @line);

my (%group, $error_msg, $gid, $groupname);

$error_msg = "";

if($in{"groupname"})
{
	$groupname = $in{"groupname"};
}
else
{
	$error_msg = $text{'error_msg_no_groupname'};
}

unless($error_msg)
{
	$gid = &local_group_exist($groupname);
	if($gid < 0)
	{
		$error_msg = $text{'error_msg_group_not_exist_local'};
		$logminor= $text{'module_name'};
		$logpriority=$text{'naslog_warning'};
		$event = $text{'groups_naslog_event_delete_fail_gname_not_exist'};
		$formatstr = sprintf $text{'groups_naslog_delete_fail_gname_not_exist'}, $groupname;	
	}
}

unless($error_msg)
{
	$group{"group"} = $groupname;
	&get_group_detail(\%group);
}

if($error_msg)
{
	#&header($text{'index_title'}, "", undef, 0, 1);
	#print "<p>", $error_msg;
	#&footer("/groups/", $text{'index'});
	if($event)
	{
		&nas_syslog($logminor, $logpriority, $event, $formatstr);
	}

	&error_setup($text{"error_title_delete_group"});
	&error($error_msg);
}
else
{
#	&header($text{'index_title'}, "", undef, 0, 1);
	
	$logminor= $text{'module_name'};
	$logpriority=$text{'naslog_info'};
	$event = $text{'groups_naslog_event_delete_success'};
	$formatstr = sprintf $text{'groups_naslog_delete_success'}, $groupname;
	&nas_syslog($logminor, $logpriority, $event, $formatstr);

	&delete_group(\%group);
	&redirect("index.cgi");
#	&footer("/groups/", $text{'index'});
}

